//---------------------------------------------------------------------------
#include "MyTXTFile.h"
#ifdef MY_BORLAND
#include <vcl.h>
#pragma hdrstop
#pragma package(smart_init)
using namespace std;
static inline void ValidCtrCheck(MyTxtFile *)
{
	new MyTxtFile(NULL);
}
#endif
//---------------------------------------------------------------------------
/*
 * Method Name  : MyTxtFile
 *
 * Synopsis     : MyTxtFile::MyTxtFile(char *FileName)
 *
 * Arguments    : char  *FileName : Name of the file for
 *
 * Description  : 
 * 
 * Returns      : 
 */
MyTxtFile::MyTxtFile(char *FileName)
{
	ifstream infile(FileName);
	char *Txt;
	int Len;
	string line;
	while (getline(infile, line))
	{
		Len = strlen(line.c_str());
		Txt = (char*)malloc(Len + 1);
		memset(Txt,0,Len + 1);
		memcpy(Txt,line.c_str(),Len);
	  Data.push_back(Txt);
	}
	infile.close();
}
//---------------------------------------------------------------------------
int MyTxtFile::GetNumLines(void)
{
//	return Main.size();
	return Data.size();
}
//---------------------------------------------------------------------------
int MyTxtFile::GetVersion(void)
{
	return MYTXTFILE_VER10;
}
//---------------------------------------------------------------------------
char *MyTxtFile::GetLines(int Index)
{
/*
	int a=0;
	list<MyCard*>::iterator CardL = CardList.begin();
	MyCard *Card;
	while(CardL !=CardList.end())
	{
		Card = *CardL;
		if(CA_ID == Card->ATR->Ident)
		{
			Card->ProcessEcm(ECM,0,DW);
			Utility->FormatDebugMsg(FULL_DEBUG,"[%s][CAM]ECM processato in %d ms",Utility->GetNow(),GetTickCount()-StartTime);
		}
		CardL++;
		a++;
	}
*/
	char *Out;
	int a=0;
	list<char*>::iterator TxtL = Data.begin();
	char *Txt;
	if(Index<Data.size())
	{
		while(TxtL != Data.end())
		{
			Txt = *TxtL;
			if(a==Index)
			{
				int Len = strlen(Txt);
				Out = (char*)malloc(Len +1);
				memset(Out,0,Len+1);
				memcpy(Out,Txt,Len);
				return Out;
			}
			TxtL++;
			a++;
		}
	}
	return NULL;	
}
//---------------------------------------------------------------------------